Conditions | 3 |
Total Lines | 19 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { CommandHandler } from '@nestjs/cqrs'; |
||
16 | |||
17 | public async execute(command: UpdateCustomerCommand): Promise<void> { |
||
18 | const { id, name } = command; |
||
19 | |||
20 | const customer = await this.customerRepository.findOneById(id); |
||
21 | if (!customer) { |
||
22 | throw new CustomerNotFoundException(); |
||
23 | } |
||
24 | |||
25 | if ( |
||
26 | name !== customer.getName() && |
||
27 | true === (await this.isCustomerAlreadyExist.isSatisfiedBy(name)) |
||
28 | ) { |
||
29 | throw new CustomerAlreadyExistException(); |
||
30 | } |
||
31 | |||
32 | customer.updateName(name); |
||
33 | |||
34 | await this.customerRepository.save(customer); |
||
35 | } |
||
37 |